<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>App下载设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="__LAYUIADMIN__/res/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__LAYUIADMIN__/res/adminui/dist/css/admin.css" media="all">
    <style>
        .admin-container {
            padding: 20px;
        }

        .layui-tab-content {
            padding: 20px 0;
        }

        .layui-form-item {
            margin-bottom: 25px;
        }

        .layui-upload-img {
            width: 100px;
            height: 100px;
            margin: 10px;
        }

        .layui-upload-list img {
            max-width: 300px;
            max-height: 200px;
        }

        .update-history-item {
            margin-bottom: 20px;
            padding: 15px;
            border: 1px solid #e6e6e6;
            border-radius: 5px;
            position: relative;
        }

        .update-history-item .remove-update {
            position: absolute;
            right: 10px;
            top: 10px;
        }

        .preview-item {
            display: inline-block;
            position: relative;
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .preview-item img {
            width: 200px;
            height: 125px;
            object-fit: cover;
            border-radius: 5px;
        }

        .preview-item .remove-preview {
            position: absolute;
            right: 5px;
            top: 5px;
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            border-radius: 50%;
            cursor: pointer;
        }

        .app-info-container {
            border: 1px solid hsl(0, 0%, 90%);
            border-radius: 5px;
            padding: 15px;
            margin-bottom: 20px;
        }
    </style>
</head>

<body>
 
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">App下载设置</div>
                    <div class="layui-card-body">
                        <form class="layui-form" lay-filter="appDownloadForm">
                            <fieldset class="layui-elem-field">
                                <legend>下载设置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">直接下载</label>
                                        <div class="layui-input-block">
                                            <div class="layui-upload">
                                                <button type="button" class="layui-btn" id="apk-upload">
                                                    <i class="layui-icon layui-icon-upload"></i> 上传APK文件
                                                </button>
                                                <div class="layui-upload-list">
                                                    <p id="apk-upload-text">当前APK: {$data.apkFilePath}</p>
                                                </div>
                                                <!-- 添加隐藏输入框存储APK文件路径 -->
                                                                                               <input type="hidden" name="apkFilePath" id="apkFilePath" value=" {$data.apkFilePath}">

                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">网盘链接</label>
                                        <div class="layui-input-inline" style="width: 60%;">
                                            <input type="text" name="cloudLink" value="{$data.cloudLink}"
                                                placeholder="网盘链接" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">提取码</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="cloudPassword" value="{$data.cloudPassword}" placeholder="提取码"
                                                autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="demo2">确认保存</button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>

        </div>
    </div>
    </div>

    <script src="__LAYUI__/layui.js"></script>
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var upload = layui.upload;
            $ = layui.$;
            // 预览图上传

            // APK文件上传
            upload.render({
                elem: '#apk-upload',
                url: '/admin/app/uploadApp',
                accept: 'file',
                exts: 'apk',
                done: function (res) {
                    // 更新显示文本
                    $('#apk-upload-text').html('当前APK: ' + res.data);
                    // 更新隐藏输入框的值
                    $('#apkFilePath').val(res.data);
                    // 更新表单值
                    form.val('appDownloadForm', {
                        'apkFilePath': res.data
                    });
                    layer.msg('APK上传成功');
                }
            });
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                $.post('/admin/app/update/?conf=app_download', field, (res) => {
                    if (res.code == 200) {
                        layer.msg('保存成功')
                    } else {
                        layer.msg(res.msg)
                    }
                })
                return false;
            });
        });


    </script>
</body>

</html>